/*
 * Copyright (c) 2013-2018 上海汇数数据. All rights reserved.
 * @(#) GenderCodeAttributeConverter.java 2018-08-06 14:01
 */

package cn.jh.common.core.support.jpa;

import cn.jh.common.core.domain.Gender;

import javax.persistence.AttributeConverter;


/**
 * @author Fuchun
 * @since 1.0
 */
public class GenderCodeAttributeConverter implements AttributeConverter<Gender, Short> {

    @Override
    public Short convertToDatabaseColumn(Gender gender) {
        return gender == null ? Gender.UNKNOWN.getCode() : gender.getCode();
    }

    @Override
    public Gender convertToEntityAttribute(Short code) {
        return Gender.of(code);
    }
}
